package pers.chao.cacheable.infrastructure.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import pers.chao.cacheable.core.factory.ICacheProcessorFactory;
import pers.chao.cacheable.core.aspect.CacheableAspect;
import pers.chao.cacheable.core.factory.CacheProcessorFactoryImpl;

/**
 * Description:
 *
 * @author W.Chao
 * @date 2021/3/28 16:51
 **/
@Configuration
public class CoreCacheableConfig {
	@Bean("cacheProcessorFactory")
	public ICacheProcessorFactory cacheProcessorFactory() {
		return new CacheProcessorFactoryImpl();
	}

	@Bean("cacheableAspect")
	@ConditionalOnBean({ICacheProcessorFactory.class})
	public CacheableAspect cacheableAspect(@Qualifier("cacheProcessorFactory") ICacheProcessorFactory factory) {
		return new CacheableAspect(factory);
	}
}
